package com.scprovider.provider.controller;

import com.sccommon.common.api.UserAPI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Map;

/**
 * 使用Feign进行远程服务调用。
 */
@RestController
public class UserFeignController implements UserAPI {
    @Value("${server.port}")
    private String port;
    @Override
    public String isAlive() {
        System.out.println("调用成功");
        return "OK!";
    }

    @Override
    public String getHi(Integer id) {
        System.out.println("Hi 你好，" + id);
        return "Hi 你好，" + id;
    }

    @Override
    public String getHi2(Integer id, String name) {
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        return "Hi " + name + ",id:" + id;
    }

    @Override
    public Map<Integer, String> getMap3(Map<String, Object> map) {
        System.out.println(map);
        return Collections.singletonMap(Integer.parseInt(map.get("id").toString()), map.get("name").toString());

    }

    @Override
    public String testHystrix() {
      System.out.println("准备睡");
        int i = 1/0;
        System.out.println(port + " 好的 ====第：" + i + "次调用");
        return "port:" + port;
    }
}
